package com.briup.app02.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.app02.bean.Category;
import com.briup.app02.bean.CategoryExample;
import com.briup.app02.dao.CategoryMapper;
import com.briup.app02.service.ICategoryService;

@Service
public class CategoryServiceImpl implements ICategoryService {
	@Autowired
	private CategoryMapper categoryMapper;
	
	@Override
	public List<Category> findAll() {
		// 模板查询
		CategoryExample example = new CategoryExample();
		return categoryMapper.selectByExample(example);
	}

	@Override
	public void saveOrUpdate(Category category) {
		if(category.getId() == null) {
			categoryMapper.insert(category);
		} else {
			categoryMapper.updateByPrimaryKey(category);
		}
	}

	@Override
	public Category findById(long id) {
		return categoryMapper.selectByPrimaryKey(id);
	}

	@Override
	public void deleteById(long id) {
		categoryMapper.deleteByPrimaryKey(id);
	}

}
